package cn.bluedot.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.bluedot.dao.VaccinationSettingDao;
import cn.bluedot.model.Pig;
import cn.bluedot.model.VaccinationSettingInfo;
import cn.bluedot.service.VaccinationSettingService;
/**
 * 疫苗接种设置实现类
 * @author hxp
 * 2019年5月6日 下午6:09:32
 */
@Service
public class VaccinationSettingServiceImpl implements VaccinationSettingService {
    @Autowired
    VaccinationSettingDao vaccinationSettingDao;
    
    @Override
    public List<Pig> queryAllPig() {
        
        return vaccinationSettingDao.queryAllPig();
    }

    @Override
    public List<Pig> queryPigByHogcote(String hogcote) {
        return vaccinationSettingDao.queryPigByHogcote(hogcote);
    }

    @Override
    public List<Pig> queryPigByPigType(String pigType) {
        return vaccinationSettingDao.queryPigByPigType(pigType);
    }
    
    
    @Override
    public List<Pig> queryPigByHogcoteAndPigType(String hogcote, String pigType) {
        HashMap<String,String> map = new HashMap<String,String>();
        map.put("hogcoteNo", hogcote);
        map.put("typeName", pigType);
        return vaccinationSettingDao.queryPigByHogcoteAndPigType(map);
    }
    
    @Override
    public void batchSaveVaccinationSettingInfo(VaccinationSettingInfo info, List<String> pigList) {
        List<VaccinationSettingInfo>  list = new ArrayList<>(16);
        for(String pigNo : pigList) {
            //为每一条记录生成一个新的VaccinationSettingInfo对象
            VaccinationSettingInfo  temp = new VaccinationSettingInfo(info.getVaccineName(), info.getInjectionWay(), 
                    info.getVaccinationUserno(), info.getUseQuantify(), info.getUnit(), info.getVaccinationIntroduce(), 
                    info.getVaccinationTime(), info.getRemindTime());
            Date date = new Date();
            temp.setCreateTime(date);
            temp.setModifyTime(date);
            temp.setPigNo(pigNo);
            list.add(temp);
        }
        vaccinationSettingDao.batchSaveVaccinationSettingInfo(list);
    }
    
    

}
